package com.ljs.spring_fastdfs.controller;

import com.ljs.spring_fastdfs.config.util.JsonResult;
import com.ljs.spring_fastdfs.config.util.UploadAndDownloadUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;

@Controller
@Api("下载")
public class Download {
    //读取配置文件自定义的路径
    @Value("${myfile.staticAccessPath}")
    String staticAccessPath;
    @Value("${myfile.uploadFolder}")
    String uploadFolder;
    @RequestMapping("/down")
    //这个是控制浏览器直接下载这个文件
    @ResponseBody
    public String download(HttpServletRequest request, Model model, @RequestParam("filename") String filename, HttpServletResponse response) throws IOException {
        System.out.println("要下载的文件"+filename);
     //   String path="E:/images/";//指定路径
        System.out.println("自己定义的路径"+uploadFolder);
        UploadAndDownloadUtil.download(uploadFolder,filename,response);


        return "下载成功";

    }

}
